﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
using Slex.Timeline;
using System.Windows.Threading;

namespace Test.Scenes {
    public partial class Progress1 : Page {
        public Progress1() {
            InitializeComponent();
            data1 = new Entityx[11];
            data2 = new Entityx[11];
            data3 = new Entityx[11];
            Loaded+=Progress1_Loaded;
            Unloaded += Progress1_Unloaded;
            sb = new Storyboard();
            timer = new DispatcherTimer();
            timer.Interval = TimeSpan.FromSeconds(.5);
            timer.Tick += timer_Tick;
            ran = new Random();
        }
        Random ran;
        void timer_Tick(object sender, EventArgs e) {
            for (int i = 0; i < 11; i++) {
                data1[i].Valued = ran.Next(300);
                data2[i].Valued = ran.Next(300);
                data3[i].Valued = ran.Next(300);
            }
            sb.Begin();
        }

        void Progress1_Unloaded(object sender, RoutedEventArgs e) {
            timer.Stop();
            sb.Stop();
            sb.Children.Clear();
        }
        Storyboard sb; DispatcherTimer timer;
        private void Progress1_Loaded(object sender, RoutedEventArgs e) {
            for (int i = 0; i < 11; i++) {
                data1[i] = new Entityx();
                data1[i].Da.Duration = TimeSpan.FromMilliseconds(400);
                Storyboard.SetTarget(data1[i].Da, LayoutRoot.Children[i]);
                Storyboard.SetTargetProperty(data1[i].Da, new PropertyPath("Width"));
                sb.Children.Add(data1[i].Da);
            }
            LayoutRoot.DataContext = data1;
            for (int i = 0; i < 11; i++) {
                data2[i] = new Entityx();
                data2[i].Da.Duration = TimeSpan.FromMilliseconds(400);
                Storyboard.SetTarget(data2[i].Da, LayoutRoot2.Children[i%11]);
                Storyboard.SetTargetProperty(data2[i].Da, new PropertyPath("Width"));
                sb.Children.Add(data2[i].Da);
            }
            LayoutRoot2.DataContext = data2;
            for (int i = 0; i < 11; i++) {
                data3[i] = new Entityx();
                data3[i].Da.Duration = TimeSpan.FromMilliseconds(400);
                Storyboard.SetTarget(data3[i].Da, LayoutRoot3.Children[i%11]);
                Storyboard.SetTargetProperty(data3[i].Da, new PropertyPath("Width"));
                sb.Children.Add(data3[i].Da);
            }
            LayoutRoot3.DataContext = data3;
            timer.Start();
        }
        Entityx[] data1;
        Entityx[] data2;
        Entityx[] data3;
        // 当用户导航到此页面时执行。
        protected override void OnNavigatedTo(NavigationEventArgs e) {
        }

    }
}
